# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import scrapy

class MiddlePipeline:
    def process_item(self, item, spider):
        return item


from scrapy.pipelines.images import ImagesPipeline

class XiaLuo(ImagesPipeline):

    def get_media_requests(self, item, info):

        for url in item['url']:
            yield scrapy.Request(url=url,meta={'title': item['title']})


    def file_path(self, request, response=None, info=None):
        uuid = request.url.split('.')[-1]  # 获取图片后缀 png jpg jif
        title = request.meta['title']
        filename = '{}.{}'.format(title,uuid)
        print(filename + '下载成功')
        return filename

